package example.strategy.symmetry;

import org.apache.log4j.Logger;
import com.scop.desensitize.encry.rreversible.symmetry.AbstractSymmetryEncry;
import com.scop.desensitize.exception.strategy.DecodeException;
import com.scop.desensitize.exception.strategy.EncodeException;
import com.scop.desensitize.strategy.rreversible.symmetry.Rc4Strategy;

import java.security.NoSuchAlgorithmException;

/**
 * @author MrPeng
 * @Desc
 * @create 2022-05-09 9:11
 */
public class Rc4StragegyDemo {

    public static Logger log = Logger.getLogger(Rc4StragegyDemo.class);

    public static void main(String[] args) throws EncodeException, DecodeException {

        String data = "scop";
        /**
         * @desc  默认密码加密
         */
        defaultEncry(data);

        //customEncry(data);
    }

    /**
     * @desc 默认执行
     * @throws NoSuchAlgorithmException
     */
    public static void defaultEncry(String data) throws EncodeException, DecodeException {
        String password = "D271FFEB9627BA0CE161F738FC8A5878D";
        AbstractSymmetryEncry rc4= Rc4Strategy.getInstance();
        String encodeStr =(String) rc4.encode(password,data);
        String decodeStr =(String) rc4.decode(password,encodeStr);

        log.info("默认密码加密--->默认数据：" + data);
        log.info("默认密码加密--->加密数据：" + encodeStr);
        log.info("默认密码加密--->解密数据：" + decodeStr);
    }


    /**
     * @desc 自定义偏移量，密码
     */
    public static void customEncry(String data) throws EncodeException, DecodeException {
        AbstractSymmetryEncry rc4= Rc4Strategy.getInstance();

        rc4.setIV_PARAMETER("12332112");
        //密码必须是16位
        rc4.setPassword("1234567812312378");

        String encodeStr = (String)rc4.encode(data);
        String decodeStr = (String)rc4.decode(encodeStr);

        log.info("自定义密码加密--->默认数据：" + data);
        log.info("自定义密码加密--->加密之后：" + encodeStr);
        log.info("自定义密码加密--->解密之后：" + decodeStr);
    }

}
